package com.tenglong.teacher.ui.adapter.viewholder;

import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.cuotibao.zhuoxiao.basics.utils.IpUtils;
import com.cuotibao.zhuoxiao.basics.utils.glide.GlideOptions;
import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.AnswerInfo;
import com.tenglong.teacher.services.hdx.CreateRequestEntity;
import com.tenglong.teacher.ui.adapter.AnswerAdapter;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;
import com.thinkcool.circletextimageview.CircleTextImageView;

public class AnswerCollectViewHolder extends BaseViewHolder<AnswerInfo> {
    private AnswerAdapter.AnswerListener listener;
    private CircleTextImageView headerImage;
    private TextView title;
    private TextView content;
    private TextView source;

    public AnswerCollectViewHolder(View itemView) {
        super(itemView);
    }
    public AnswerCollectViewHolder(View itemView,AnswerAdapter.AnswerListener listener){
        this(itemView);
        this.listener = listener;
        initView();
        setListeners();
    }

    private void setListeners() {
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onAnswerClick(getAdapterPosition());
                }
            }
        });
    }

    private void initView() {
        headerImage = itemView.findViewById(R.id.headerImage);
        title = itemView.findViewById(R.id.title);
        content = itemView.findViewById(R.id.content);
        source = itemView.findViewById(R.id.source);
    }

    @Override
    public void setLayoutInfo(AnswerInfo info) {
        RequestOptions options = GlideOptions.getGlideRequestOptions().
                error(R.drawable.setting_image_defauft_header).
                placeholder(R.drawable.header_image_loading);
        Glide.with(itemView.getContext())
                .load(IpUtils.getImageUrl(info.stuPhotoUrl))
                .apply(options)
                .into(headerImage);
        title.setText(info.studentname);
        content.setText(info.firsttextmsg);
        source.setText(info.teachername+"老师已解答");
    }
}
